//
//  TableViewViewController.m
//  TableView
//
//  Created by feng liu on 11-1-13.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TableViewViewController.h"
#import "CustomCell.h"

@implementation TableViewViewController

@synthesize list;

- (void)viewDidLoad {
	//添加数据到数组里
	NSArray *array = [[NSArray alloc] initWithObjects:@"January",@"February",
					  @"March",@"April",@"May",@"June",@"July",@"August",
					  @"September",@"October",@"November",@"December",nil];
	//把新数组分配给list
	self.list = array;
	[array release];	
    [super viewDidLoad];
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	self.list = nil;
	[super viewDidUnload];
}


- (void)dealloc {
	[list release];
    [super dealloc];
}

#pragma mark -
#pragma mark TableView 数据源委托

//tableview一共有多少行数据
- (NSInteger)tableView:(UITableView *)tableView 
 numberOfRowsInSection:(NSInteger)section
{
	return [list count];
}
//没行数据都是什么内容
- (UITableViewCell *)tableView:(UITableView *)tableView 
		 cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *tableViewIdentifier = @"tableViewIdentifier";
	//如果没有可重用的单元，就从nib中加载一个。
	CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:tableViewIdentifier];
	if (cell == nil) {
		//加载nib时，获得一个数组，其中包含nib的所有对象，
		NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
		//迭代nib中所有对象来查找customcell类的实例
	for (id oneObject in nib) {
		if ([oneObject isKindOfClass:[CustomCell class]]) {
			cell=(CustomCell *)oneObject;
		}
	}	
	}
	NSInteger row = [indexPath row];
	cell.textOne.text = [list objectAtIndex:row];
	cell.textTwo.text = @"this";

	return cell;
}
//重新定义cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 50;
}

@end
